package com.shigen.demo.controller;


import com.shigen.demo.bean.Result;
import com.shigen.demo.entity.Visitors;
import com.shigen.demo.entity.req.VisitorsReq;
import com.shigen.demo.service.IVisitorsService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import javax.validation.Valid;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping(value = "visitors")
@Api(tags = "游客数据")
public class VisitorsController {

  @Resource
  private IVisitorsService visitorsService;

  @PostMapping(value = "query")
  @ApiOperation(value = "分页查询数据")
  public Result getByPage(@RequestBody @Valid VisitorsReq.QueryItem queryItem) {
    return Result.ok(visitorsService.getByPage(queryItem));
  }

  @PostMapping(value = "public/add")
  @ApiOperation(value = "提交访客数据的接口")
  public Result addVisitors(@RequestBody Visitors visitors, HttpServletRequest request) {
    int insert = visitorsService.addVisitor(visitors, request);
    return insert > 0 ? Result.ok("成功") : Result.err("失败");
  }
}
